package cn.gson.work.controller;

import cn.gson.work.model.pojos.Trecord;
import cn.gson.work.model.service.TrecordService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class TrecordController {
    @Autowired
    TrecordService trs;

    /**
     * 分页条件模糊查询
     * @param page
     * @param size
     * @param rno
     * @return
     */
    @RequestMapping("/findTrecord")
    @ResponseBody
    public Map<String, Object> findTrecord(@RequestParam("page") Integer page,
                                        @RequestParam("size") Integer size,
                                        @RequestParam("rno") String rno) {
        System.out.println(page+"================"+size);
        Page<Object> obj = PageHelper.startPage(page, size);
        trs.findTrecord(rno);
        Map<String, Object> map = new HashMap<>();
        map.put("total", obj.getTotal());
        map.put("rows", obj.getResult());
        return map;
    }

    /**
     * 通过编号归还案卷
     * @param rno
     */
    @RequestMapping("/delTrecord")
    @ResponseBody
    public void delTrecord(@RequestParam("id") long rno){
        trs.delTrecord(rno);
    }

    /**
     * 在案卷借阅时，对案卷借阅进行添加
     * @param trecord
     */
    @RequestMapping("/addTrecord")
    @ResponseBody
    public void addTrecord(@RequestBody Trecord trecord){
        trs.addTrecord(trecord);
    }

    /**
     * 通过编号查询案卷数据，与案卷借阅的添加相关
     * @param rno
     * @return
     */
    @RequestMapping("/findTrecordByRno")
    @ResponseBody
    public List<Trecord> findTrecordByRno(@RequestParam("rno") String rno){
        return trs.findTrecordByRno(rno);
    }
}
